package com.example.gallery;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.board.R;



public class GalleryAdapter extends ArrayAdapter<ImageDTO>{
	static final String TAG = "GalleryAdapter";
	ArrayList<ImageDTO> list;

	
	public GalleryAdapter(Context context, int resource, ArrayList<ImageDTO> list) {
		super(context, resource, list);
		this.list = list;
	}

	@SuppressWarnings("null")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if(v == null){
			LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			
			v = vi.inflate(R.layout.iv_row, null);
		}
		LinearLayout layout =(LinearLayout) v.findViewById(R.id.layout_iv_row);
		notifyDataSetChanged();
		ImageDTO image = list.get(position);
		notifyDataSetChanged();
		Log.i(TAG, "���� �� �� : "+list.size());
		if(image != null){
			ImageView iv = null;
			Bitmap bitmap = BitmapFactory.decodeFile(image.getNAME());
			iv.setImageBitmap(bitmap);
			layout.addView(iv, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		}
		return v;
	}
	

}
